myapp.controller('registerController', function ($scope,registerService) {
    $scope.content = '发送验证码'

    var active = true
    var second = 60
    var secondInterval
    $scope.registerBtn = function () {
        if (active == false) {
            return ;
        }
        if ($scope.telephone == null || $scope.telephone=="") {
            alert("手机号不能为空!")
            return ;
        }
        registerService.verifyPhone($scope.telephone).success(
            function (data) {
                if (data == 'phoneFormat') {
                    alert("手机格式错误!")
                }else if (data == "error"){
                    alert('网络错误,请检查网络')
                } else if (data == 'OK'){
                    alert('发送成功请检查手机')
                }

            }
        )

        active =false
        secondInterval=setInterval(function () {
            if (second < 0){
                $scope.content = "重发验证码"
                //必须使用这个才能更新视图 ,要不然没有效果的
                $scope.$digest()
                active = true
                second=60
            } else{
                $scope.content = second + "秒后重新发送"
                //必须使用这个才能更新视图 ,要不然没有效果的
                $scope.$digest()
                second--
            }
        },1000)

    }
    //表单元素的二次认证
     $scope.register=function(){
         var prop = $("input[type='checkbox']").prop("checked");
         if (! prop) {
             alert("请勾选协议!")
             return ;
         }else if ($scope.telephone == null || $scope.telephone == ''){
              alert("请填写手机号")
             return ;
         }else if ($scope.password == null || $scope.password == ''){
             alert('请填写密码')
             return ;
         }else if ($scope.twopassword == null || $scope.twopassword == '' || $scope.twopassword != $scope.password){
             alert("两次密码不一致")
             return
         }else if ($scope.email == null || $scope.email == ''){
             alert("请填写邮箱")
             return
         } else{
             $('#registerForm').submit()
         }



     }



})